﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using java.lang;
using org.apache.commons.lang3;
using org.slf4j;
using org.w3c.dom;
using String = System.String;

namespace Game.utils
{
    public class XMLUtil
    {
        private static Logger _log = LoggerFactory.getLogger(typeof (XMLUtil));
        public static String getAttributeValue(Node n, String item)
	    {
		    var d = n.getAttributes().getNamedItem(item);
		    if (d == null)
		    {
			    return StringUtils.EMPTY;
		    }
		    var val = d.getNodeValue();
            return val ?? StringUtils.EMPTY;
	    }
        public static bool getAttributeBooleanValue(Node n, String item, bool dflt)
	    {
		    var d = n.getAttributes().getNamedItem(item);
		    if (d == null)
		    {
			    return dflt;
		    }
		    var val = d.getNodeValue();
		    return val == null ? dflt : java.lang.Boolean.parseBoolean(val);
	    }
        public static int getAttributeIntValue(Node n, String item, int dflt)
	    {
		    var d = n.getAttributes().getNamedItem(item);
		    if (d == null)
		    {
			    return dflt;
		    }
		    var val = d.getNodeValue();
		    return val == null ? dflt : Integer.parseInt(val);
	    }
        public static long getAttributeLongValue(Node n, String item, long dflt)
	    {
		    var d = n.getAttributes().getNamedItem(item);
		    if (d == null)
		    {
			    return dflt;
		    }
		    var val = d.getNodeValue();
		    return val == null ? dflt : Long.parseLong(val);
	    }
    }
}
